<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        编辑模板
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
</head>
<style>

</style>

<body>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add" lay-filter="updateInfo">
        <div class="layui-tab-content">

            <div class="layui-form-item" style="margin-top: 8px;">
                <label class="layui-form-label">模板名称<span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" name="name" lay-filter="name" lay-verify="required"  class="layui-input" placeholder="模板名称">
                </div>
            </div>
            <div class="layui-form-item layui-form-text" style="margin-top: 8px;">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="memo" placeholder="备注信息" class="layui-textarea"></textarea>
                </div>
            </div>

        </div>

        <div style="text-align: center" class="layui-form-item">
            <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                确定
            </button>
        </div>

    </form>
</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var templateId = getQueryVariable("templateId");

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;

            let request = {
                url: 'xa/template/findTemplateById',
                data: {
                    userId: $userId,
                    id:templateId
                },
            };
            sendRequest(request, (data) => {
                if (data.code === 0) {
                    form.val('updateInfo', {

                        "name": data.data.name,
                        "memo":data.data.memo
                    });
                } else {
                    layer.alert(data.msg, {
                        icon: 2
                    })
                }
            });

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = templateId;
                    form.level = 1;

                    let request = {
                        url: 'xa/template/addAndUpdateTemplate',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {

                            if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    let index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.location.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }

                    });
                    return false;
                });


        });


    const vm = new Vue({
        el: "#app",
        data: {
            billing: {
                id: null,
                name: null,
                taxpayerIdentificationNumber: null,
                addressAndTelephoneNumber: null,
                bankAndAccountNumber: null,
                contactInformation: null,
                billType: null,
                faceValue: null,
                billingDate: null,
                taxPoint: null,
                faceTax: null,
                associatedCredentials: null,
                associatedCredentialsId: null,
                remark: null,
                billAttachment: '',
                pictureOfReceipt: '',
                type: null,
                nature: null
            }
        },
        created() {
        },
        computed: {
            bindSrcBillAttachment() {
                return vm.billing.billAttachment.startsWith('upload') ? $baseUrl +
                    'other/viewUploadFile?id=' + vm.billing.billAttachment : '../../images/upload.png';
            },
            bindSrcPictureOfReceipt() {
                return vm.billing.pictureOfReceipt.startsWith('upload') ? $baseUrl +
                    'other/viewUploadFile?id=' + vm.billing.pictureOfReceipt : '../../images/upload.png';
            }
        },
        methods: {
            uploadBillAttachment() {
                this.$refs.billAttachment.click()
            },
            uploadPictureOfReceipt() {
                this.$refs.pictureOfReceipt.click()
            },
            getFile(event, type) {

                var file = event.target.files[0];

                let qualified = ".jpg .png .bmp .jpeg .gif .bmp";
                let fineName = file.name;
                if (!fineName.includes(".") || !qualified.includes(fineName.substr(fineName.lastIndexOf(".")))) {
                    layer.alert("上传类型错误，只支持.jpg .png .bmp");
                    return;
                }

                var formData = new FormData();
                formData.append('photo', file);
                formData.userId = $userId;
                $.ajax({
                    url: $baseUrl + "/other/fileUpload",
                    type: "post",
                    headers: {
                        "token": $token,
                    },
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (res) {
                        type === 'billAttachment' ? vm.billing.billAttachment = res.data :
                            vm.billing.pictureOfReceipt = res.data;
                        layer.alert(res.msg);
                    },
                    error: function (res) {
                        layer.alert(res.msg);
                    }
                });
            }
        },


    });

</script>

</body>

</html>
